package com.kupurui.asteacher.ui.job;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.frame.util.AppJsonUtil;
import com.android.frame.util.Toolkit;
import com.android.frame.view.gridview.GridViewForScrolview;
import com.kupurui.asteacher.R;
import com.kupurui.asteacher.adapter.CorrectAdapter;
import com.kupurui.asteacher.adapter.CorrectUnAdapter;
import com.kupurui.asteacher.bean.CorrectDetailsInfo;
import com.kupurui.asteacher.bean.CorrectInfo;
import com.kupurui.asteacher.http.Teacher;
import com.kupurui.asteacher.ui.BaseAty;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

/**
 * 批改详情
 * Created by Administrator on 2017/7/25.
 */

public class CorrectDetailsAty extends BaseAty {

    @Bind(R.id.iv_back)
    ImageView ivBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_right)
    TextView tvRight;
    @Bind(R.id.gridview_uncorrect)
    GridViewForScrolview gridviewUncorrect;
    @Bind(R.id.gridview_correct)
    GridViewForScrolview gridviewCorrect;
    @Bind(R.id.ll_correct)
    LinearLayout llCorrect;
    @Bind(R.id.ll_un_correct)
    LinearLayout llUnCorrect;


    CorrectDetailsInfo correctDetailsInfo;
    List<CorrectDetailsInfo.YiPigaiBean> correctList;
    List<CorrectDetailsInfo.NoPigaiBean> unCorrectList;
    CorrectAdapter adapter;
    CorrectUnAdapter unAdapter;


    private String id = "";
    private String q_id = "";

    @Override
    public int getLayoutId() {
        return R.layout.correct_details_aty;
    }

    @Override
    public void initData() {
        if (getIntent().getExtras()!=null){
            id = getIntent().getStringExtra("id");
            q_id = getIntent().getStringExtra("q_id");
        }
        correctList = new ArrayList<>();
        unCorrectList = new ArrayList<>();
        adapter = new CorrectAdapter(this,correctList,R.layout.correct_details_item);
        unAdapter = new CorrectUnAdapter(this,unCorrectList,R.layout.correct_details_item);
        gridviewUncorrect.setAdapter(unAdapter);
        gridviewCorrect.setAdapter(adapter);
    }

    @Override
    public void requestData() {
        showLoadingContent();
        new Teacher().singleDetail(id,q_id,this,0);
    }

    @OnClick({R.id.iv_back,R.id.tv_right})
    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()){
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_right:
                Bundle bundle = new Bundle();
                bundle.putString("q_id",q_id);
                startActivity(ScriptTopicAty.class, bundle);
                break;
        }
    }

    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        switch (what){
            case 0:
                correctDetailsInfo = AppJsonUtil.getObject(result,CorrectDetailsInfo.class);
                correctList.clear();
                correctList.addAll(correctDetailsInfo.getYi_pigai());
                if (Toolkit.listIsEmpty(correctList)){
                    llCorrect.setVisibility(View.GONE);
                }else{
                    llCorrect.setVisibility(View.VISIBLE);
                }
                unCorrectList.clear();
                unCorrectList.addAll(correctDetailsInfo.getNo_pigai());
                if (Toolkit.listIsEmpty(unCorrectList)){
                    llUnCorrect.setVisibility(View.GONE);
                }else{
                    llUnCorrect.setVisibility(View.VISIBLE);
                }
                adapter.notifyDataSetChanged();
                unAdapter.notifyDataSetChanged();
                break;
        }
        super.onSuccess(result, call, response, what);
    }
}
